package com.edu.bean;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;

import javax.validation.constraints.*;
import java.util.Date;

public class User {

    private int userId;

    @NotEmpty(message = "用户名必填")
    @Length(min = 6,max=10,message = "用户名长度必须在6-10位之间")
    private String username;

    @NotEmpty(message = "密码必填")
    @Length(min = 6,max=10,message = "密码长度必须在6-10位之间")
    private String password;

    @Range(min=1,max=120,message = "你怕是妖怪吧，年龄应该在0-120之间")
    private int age;

    @NumberFormat(style = NumberFormat.Style.PERCENT)
    private double workRate;

    @Email(message = "必须是邮箱格式")
    private String email;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public double getWorkRate() {
        return workRate;
    }

    public void setWorkRate(double workRate) {
        this.workRate = workRate;
    }

    @Min(value = 1800,message = "工资标准不能违反劳动法")
    private double salary;

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Past(message = "你不可能出生在未来")
    @DateTimeFormat(pattern = "yyyy-MM-dd",fallbackPatterns = {"yyyy/MM/dd","yyyy\\MM\\dd","yyyy年MM月dd日"})
    private Date birthday;

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "userId=" + userId +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                '}';
    }

    public User(String username, String password, int age) {
        this.username = username;
        this.password = password;
        this.age = age;
    }

    public User() {

    }
}
